// pages/service/pre-consultation/pre-consultation.ts


// 1) data 的类型
interface Data {
  statusBarHeight: number;
  draft: string;
  messages: Msg[];
  scrollToId: string;
  showPicker: boolean;
  systolicList: string[];
  diastolicList: string[];
  pickerIndex: [number, number];
}

// 2) 自定义实例方法的类型（把你自己写的非生命周期方法声明进去）
interface Custom {
  scrollBottom(): void;
  onBack():void
  // 以后如果你再加 onPickerConfirm / onSend 等自定义方法，也建议同步加到这里
}

// 3) Page 传入两个泛型：Data 和 Custom
Page<Data, Custom>({
  data: {
    statusBarHeight: 20,
    draft: '',
    messages: [
      { id: 1, side: 'right', text: '我的血压今天突然升高了' },
      { id: 2, side: 'left',  text: '请问高血压是首次发作还是复发？' },
      { id: 3, side: 'right', text: '复发' },
      { id: 4, side: 'left',  text: '您的血压是多少？' }
    ],
    scrollToId: 'bottom-anchor',

    showPicker: true,
    // 注意：空数组在 TS 中会被推成 never[]，这里显式断言为 string[]
    systolicList: [] as string[],
    diastolicList: [] as string[],
    pickerIndex: [15, 10]
  },
  onBack() {
    wx.navigateBack({
      delta: 1   // 返回上一级（默认就是 1，其实可以省略）
    })
  },

  onLoad() {
    const sys = wx.getSystemInfoSync();
    this.setData({ statusBarHeight: sys.statusBarHeight || 20 });

    // 生成血压刻度（显式声明类型避免推断为 never[]）
    const sysArr: string[] = [];
    const diaArr: string[] = [];
    for (let s = 90; s <= 200; s += 5) sysArr.push(String(s));
    for (let d = 50; d <= 120; d += 5) diaArr.push(String(d));

    this.setData({
      systolicList: sysArr,
      diastolicList: diaArr,
      pickerIndex: [sysArr.indexOf('120'), diaArr.indexOf('75')] as [number, number]
    });
  },

  // 你的自定义方法 —— 已在 Custom 里声明
  scrollBottom() {
    this.setData({ scrollToId: 'bottom-anchor' });
  },

  onReady() {},
  onShow() {},
  onHide() {},
  onUnload() {},
  onPullDownRefresh() {},
  onReachBottom() {},
  

  onShareAppMessage() {
    return {} as WechatMiniprogram.Page.ICustomShareContent;
  }
});
